import requests

base_url = "http://123.207.53.152:8000"


def login():
    username = "admin"
    password = "admin123"
    req = requests.post(base_url + "/api/v1/login", data={"username": username, "password": password})
    assert req.status_code == 200, "登录失败"
    assert req.json().get("status") == "success", "登录失败"
    token = req.json().get("data").get("access_token")
    print("token == ", token)
    return token


def send_email():
    token = login()
    headers = {"Authorization": "Bearer " + token}
    req = requests.post(base_url + "/api/v1/admin/send_email/", headers=headers, params={"subscription_id": 3,
                                                                                         "content": '{"stocks": "1,2,3", "sale_stocks": "1,2,3", "buy_stocks": "2,3,4", "today": "2024-09-30"}'})
    assert req.status_code == 200, "发送失败" + req.text
    print(req.json())
    print("发送成功")


if __name__ == "__main__":
    send_email()


